/**
* All Rights Reserved , Copyright (C) 2021 , 青岛鼎信通讯股份有限公司
*
* MpmProjectReviewServiceAuto
* 项目复盘结项
*
* 修改纪录
* 2021-01-18 版本：1.0 wudaliang 创建。
* @version 版本：1.0
* @author 作者：wudaliang
* 创建日期：2021-01-18
*/

package com.topscomm.mpm.service.impl.auto;

import javax.annotation.Resource;

import com.alibaba.fastjson.JSONArray;
import com.topscomm.basic.IBasicDao;
import com.topscomm.mpm.pojo.MpmProjectEntity;
import com.topscomm.mpm.service.impl.MpmProjectService;
import com.topscomm.pub.util.ConvertUtil;
import com.topscomm.pub.util.SpringUtil;
import com.topscomm.pub.util.StringBufferProxy;
import com.topscomm.tap.common.DatacodeCache;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.topscomm.mpm.*;
import com.topscomm.mpm.pojo.MpmProjectReviewEntity;
import com.topscomm.mpm.dao.IMpmProjectReviewDao;


public class MpmProjectReviewServiceAuto extends MpmService<MpmProjectReviewEntity,IMpmProjectReviewDao> {

	/**
	 * @author: wudaliang
	 * @date: 2021-01-18
	 * @param mapRow
	 * @description:设置字段显示值
	 * @modify:
	 */
	@Override
	public void setDispFields(Map<String, Object> mapRow, DatacodeCache datacodeCache) {
		String temp;
		if (mapRow.get("settlementmoney") != null) {
			temp = mapRow.get("settlementmoney").toString();
			mapRow.put("dispsettlementmoney", datacodeCache.getValueDynamic("Ehrrelatetype", temp, "code", "name"));
		}
		if (mapRow.get("flowid") != null) {
			temp = mapRow.get("flowid").toString();
			mapRow.put("dispflowid", datacodeCache.getValueDynamic("ApprovalFlow_MpmProjectReview", temp, "id", "name"));
		}
		if (mapRow.get("state") != null) {
			temp = mapRow.get("state").toString();
			mapRow.put("dispstate", datacodeCache.getValueDynamic("TapApprovalBillState", temp, "code", "name"));
		}
		if (mapRow.get("enabled") != null) {
			temp = mapRow.get("enabled").toString();
			mapRow.put("dispenabled", datacodeCache.getValueDynamic("CboYesNo", temp, "code", "name"));
		}

		if (mapRow.get("endtype") != null) {
			temp = mapRow.get("endtype").toString();
			mapRow.put("dispendtype", datacodeCache.getValueDynamic("MpmEndType", temp, "code", "name"));
		}
		if (mapRow.get("iswinbid") != null) {
			temp = mapRow.get("iswinbid").toString();
			mapRow.put("disiswinbid", datacodeCache.getValueDynamic("MpmIsWinBid", temp, "code", "name"));
		}
		if (mapRow.get("projectresult") != null) {
			temp = mapRow.get("projectresult").toString();
			mapRow.put("dispprojectresult", datacodeCache.getValueDynamic("MpmProjectResult", temp, "code", "name"));
		}
		if (mapRow.get("thisbidscore") != null) {
			temp = mapRow.get("thisbidscore").toString();
			mapRow.put("dispthisbidscore", datacodeCache.getValueDynamic("MpmReviewThisBidScore", temp, "code", "name"));
		}
		if (mapRow.get("havebidscoredata") != null) {
			temp = mapRow.get("havebidscoredata").toString();
			mapRow.put("disphavebidscoredata", datacodeCache.getValueDynamic("MpmReviewBidScore", temp, "code", "name"));
		}
		if (mapRow.get("productrange") != null) {
			List<Map> productRangeList = JSONArray.parseArray(ConvertUtil.convertToString(mapRow.get("productrange")), Map.class);
			Map<String, List<Map>> lineMap = productRangeList.stream().collect(Collectors.groupingBy(item -> ConvertUtil.convertToString(item.get("line"))));
			List<String> resList = new ArrayList<>();
			int count = 1;
			for (Map.Entry<String, List<Map>> entry : lineMap.entrySet()) {
				String productLine = datacodeCache.getValueDynamic("ProductLine", entry.getKey(), "code", "name");
				String product = entry.getValue().stream().map(item -> ConvertUtil.convertToString(item.get("productType"))).collect(Collectors.joining(";"));
				resList.add(count + "、" + productLine + "：" + product + ";");
				count++;
			}
			mapRow.put("productrangelist", resList);
		}
		if (mapRow.get("thisbidlist") != null) {
			temp = mapRow.get("thisbidlist").toString();
			mapRow.put("dispthisbidlist", datacodeCache.getValueDynamic("MpmThisBidList", temp, "code", "name"));
		}
		if (mapRow.get("bidmark") != null) {
			temp = mapRow.get("bidmark").toString();
			mapRow.put("dispbidmark", datacodeCache.getValueDynamic("MpmBidMark", temp, "code", "name"));
		}
		if (mapRow.get("smallbidscore") != null) {
			temp = mapRow.get("smallbidscore").toString();
			mapRow.put("dispsmallbidscore", datacodeCache.getValueDynamic("MpmSmallBidScore", temp, "code", "name"));
		}
		if (mapRow.get("expertlist") != null) {
			temp = mapRow.get("expertlist").toString();
			mapRow.put("dispexpertlist", datacodeCache.getValueDynamic("MpmExpertList", temp, "code", "name"));
		}
	}

	@Override
	@Resource(name = "mpmProjectReviewDao")
	public void setDao(IBasicDao<MpmProjectReviewEntity> dao) {
		super.setDao(dao);
	}
}
